/* Copyright (c) 2008-2009 -- CommonsWare, LLC

	 Licensed under the Apache License, Version 2.0 (the "License");
	 you may not use this file except in compliance with the License.
	 You may obtain a copy of the License at

		 http://www.apache.org/licenses/LICENSE-2.0

	 Unless required by applicable law or agreed to in writing, software
	 distributed under the License is distributed on an "AS IS" BASIS,
	 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	 See the License for the specific language governing permissions and
	 limitations under the License.
*/
	 
package com.jokerhung.mymoney;

import android.content.ContentValues;
import android.content.Context;
// import android.database.Cursor;
// import android.database.SQLException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
// import android.hardware.SensorManager;

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME="mymoney.db";
		
	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, 1);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE users (_id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT);");
		db.execSQL("CREATE TABLE transactions (_id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, date DATE, fromfor TEXT, amount INTEGER, category_id INTEGER );");
		db.execSQL("CREATE TABLE categories (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT );");
				
		ContentValues cv=new ContentValues();
		
		/*
		cv.put("username", "jokerhung");
		cv.put("password", 123);
		cv.put("date", "20/09/1986");
		db.insert("users", "username", cv);
		
		cv.put("username", "jokerhung1");
		cv.put("password", 1234);
		cv.put("date", "20/09/1986");
		db.insert("users", "username", cv);
		*/
	
		cv.put("user_id", 1);
		cv.put("date", "20/09/1986");
		cv.put("fromfor", "jokerhung");
		cv.put("amount", 500);
		cv.put("category_id", 99);
		db.insert("transactions", "fromfor", cv);
		
		cv.put("user_id", 1);
		cv.put("date", "21/09/1986");
		cv.put("fromfor", "jokerhung");
		cv.put("amount", 400);
		cv.put("category_id", 98);
		db.insert("transactions", "fromfor", cv);
		
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		android.util.Log.w("Constants", "Upgrading database, which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS constants");
		onCreate(db);
	}
}